<template>
	<view>
		<!-- 顶部tab导航栏 -->
		<scroll-view scroll-x class="tab_scroll">
			<view class="scroll_list">
				<view class="scroll_item" :class="item.type==TabCur?'scroll_item_active':''" v-for="(item,index) in tabDate" :key="index"
				 @tap="tabSelect(item)">
					{{ tabName(item.type) }}
				</view>
			</view>
		</scroll-view>
		
		<view class="tab_content">
			<u-parse :html="tabContent.content"></u-parse>
		</view>
		
		<view class="detail_function">
			<view>
				<img src="/static/home/view.png" alt="浏览" />
				{{ tabContent.view }}
			</view>
			<view @click="addLikes">
				<u-icon :color="likeState" style="margin-right: 10rpx;" name="thumb-up-fill" size="22"></u-icon>
				{{ tabContent.likes }}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				TabCur: 1,
				tabDate:[],
				tabContent:{},
				likeState:'#595959'
			}
		},
		watch:{
			TabCur(nl,ol){
				let index = this.tabDate.findIndex(item => item.type == this.TabCur);
				if(index!=-1){
					this.tabContent = this.tabDate[index];
					this.view(this.tabContent.id);
					this.tabContent.view++;
				}
			}
		},
		methods: {
			//tab切换
			tabSelect(item) {
				this.TabCur = item.type;
				this.likeState = '#595959';
			},
			// 获取导航列表数据
			async getTabNav(){
				let res = await this.$api.getCarProduct();
				if(!res?.success) return;
				this.tabDate = res.result.records.reverse();
			},
			tabName(type){
				switch(type){
					case 1: return '改色膜';
					case 2: return '隐形车衣';
					case 3: return '隔热膜';
					case 4: return 'TPU改色';
					case 5: return '店端VIS';
				}	
			},
			// 浏览
			view(id){
				this.$api.viewById({id:id});
			},
			// 点赞
			addLikes(){
				const id = this.tabContent.id;
				if(this.likeState==='#595959')this.likeState = '#FE020E';
				this.$api.likesById({id:id});
				this.tabContent.likes++;
			}
		},
		async onLoad(options){	
			await this.getTabNav();
			if(options?.type) this.TabCur = options.type;
			else this.TabCur = this.tabDate[0].type;
		}
	}
</script>

<style>
	page{
		/* background-color: #1C1C1C; */
	}
</style>

<style scoped lang="scss">
.tab_scroll{
	width: 100%;
	height: 88rpx;
	background-color: #1C1C1C;
	// margin-bottom: 8rpx;
	white-space: nowrap;
	.scroll_list{
		display: flex;
		height: 100%;
		align-items: center;
		padding:0rpx 15rpx;
		.scroll_item{
			min-width: 136rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #969799;
			display: flex;
			align-items: center;
			justify-content: center;
			height: 100%;
			line-height: 40rpx;
			border-bottom: 6rpx #969799 solid;
			margin: 15rpx;
			text-align: center;
			border-bottom-left-radius: 3rpx;
			border-bottom-right-radius: 3rpx;
		}
		.scroll_item_active{
			color: #FFFFFF;
			border-bottom-color: #FBCB11;
		}
	}
}
.tab_content{
	width: 100%;
}
.detail_function{
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: flex-end;
	font-family: DIN, DIN;
	font-weight: 400;
	font-size: 22rpx;
	color: #595959;
	margin-top: 20rpx;
	padding-bottom: 30rpx;
	view{
		margin-right: 32rpx;
		display: flex;
		align-items: center;
		img{
			width: 22rpx;
			height: 22rpx;
			margin-right: 10rpx;
		}
	}
}
</style>
